home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- *
- * PROGRAM NAME: PLAYVOCM.C
- *
- * COMPILER: Borland/Turbo C/C++
- *
- * DESCRIPTION: Plays a .VOC file from the conventional memory using
- * the CT-VOICE.DRV driver (accessed from SBSIM). To run
- * the program, type the following at the command line:
- *
- * PLAYVOCM FILENAME
- *
- * Where FILENAME is the drive/path/filename of the .VOC
- * file to play.
- *
- * NOTE: SBSIM driver must be loaded before running this program.
- *
- * WARNING: This program does NOT support files larger than 64KB!
- *
- *********************************************************************/
- #define HEADER_OFFSET 0x1A
- #define VOC_MEM_DRIVER 0x04
-
- #include <ctype.h>
- #include <conio.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <io.h>
- #include "drvrfunc.c"
- #include "drvrfunc.h"
-
-
- /********************************************************************/
- void main(int argc, char **argv)
- {
- char *Buffer,
- Command,
- UserQuit;
-
- long Filesize;
- int FileHandle;
- SIMERR RetValue;
-
- if (argc != 2) // argc = no. of parameters entered on command line
- {
- puts("Command line must contain EXACTLY ONE filename parameter!");
- return; // Terminate program
- }
-
-
- /*--- SEE IF SBSIM DRIVER HAS LOADED ------------*/
- SIMint = FindDvr("SBSIM", 0x0103); // Get SBSIM's interrupt no.
- if (SIMint == 0)
- {
- puts("SBSIM driver not loaded!");
- return; // Terminate program
- }
-
- /*--- SEE IF CT-VOICE.DRV DRIVER HAS LOADED -------*/
- if (!(GetDrvrs() & VOC_MEM_DRIVER))
- {
- puts("CT-VOICE.DRV not loaded!");
- return; // Terminate program
- }
-
-
- /*--- OPEN FILE SPECIFIED ON COMMAND LINE (STORED IN argv[1] ------*/
- if ((FileHandle = _open(argv[1], O_BINARY | O_RDONLY)) == -1)
- {
- printf("FILE: %s not successfully opened!\n", argv[1]);
- return; // Terminate program
- }
-
- /*--- GET THE FILE SIZE -------------------------*/
- Filesize = filelength(FileHandle);
- if (Filesize > 65535)
- {
- puts("File size > 64KB not supported!");
- return; // Terminate program
- }
-
-
- /*--- ALLOCATE BUFFER AND LOAD IT FROM FILE -----------*/
- if ((Buffer = (char *) malloc((size_t) Filesize)) == NULL)
- {
- puts("Memory buffer not allocated!");
- _close(FileHandle);
- return; // Terminate program
- }
- _read(FileHandle, (void *) Buffer, (unsigned) Filesize);
- _close(FileHandle); // Done with the file, close it!
-
-
- /*--- StartSnd() INITIALIZES THE CT-VOICE DRIVER -----------*/
- RetValue = StartSnd(MemVoice, (void far *) (Buffer + HEADER_OFFSET), NULL,
- NULL);
- if (RetValue != SIMerr_NoErr)
- {
- printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
- free(Buffer); // Deallocate memory allocated by malloc()
- return; // Terminate program
- }
-
- /*--- StartSnd() BEGINS PLAYING OF THE FILE ----------*/
- RetValue = PlaySnd(MemVoice);
- if (RetValue != SIMerr_NoErr)
- {
- printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
- free(Buffer); // Deallocate memory allocated by malloc()
- return; // Terminate program
- }
-
-
- clrscr(); // Clear screen
- printf("\n\n\n\n\n SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:\n\n");
- printf(" (P)ause\n");
- printf(" (R)esume\n");
- printf(" (Q)uit\n");
-
- UserQuit = FALSE;
-
- /*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*/
- do
- {
- if (kbhit()) // Was a key pressed?
- {
-
- Command = toupper(getch()); // Get char typed & convert to upper case
- if (Command == 'P')
- PauseSnd(MemVoice);
- else if (Command == 'R')
- ResumeSnd(MemVoice);
- else if (Command == 'Q')
- UserQuit = TRUE;
- }
- // Exit do-while loop if file is done playing or user typed 'Q'
- } while (GetSndStat(MemVoice) != 0 && UserQuit == FALSE);
-
-
- /*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*/
- if (GetSndStat(MemVoice) != 0 && UserQuit == TRUE)
- StopSnd(MemVoice);
-
- free(Buffer); // Deallocate memory allocated by malloc()
- return;
- }
-